package com.iflysse.services.impl;

import com.iflysse.mapper.ClassMapper;
import com.iflysse.pojo.bo.resp.ClassBoResp;
import com.iflysse.pojo.bo.resp.ClassListBoResp;
import com.iflysse.pojo.po.resp.ClassPoResp;
import com.iflysse.pojo.vo.resp.ClassListVoResp;
import com.iflysse.services.IClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * TODO
 *
 * @author My
 * @date 2021/10/21 14:42
 */
@Service
public class ClassServiceImpl implements IClassService {

    @Autowired
    ClassMapper classMapper;


    @Override
    public ClassListBoResp loadAllClasses() {
        //从数据库中获取所有的行政班
        List<ClassPoResp> allClass = classMapper.getAllClass();
        ClassListBoResp classListBoResp = new ClassListBoResp();
        List<ClassBoResp> classBoRespList = new ArrayList<>();
        for(int i=0;i<allClass.size();i++){
            ClassPoResp classPoResp = allClass.get(i);
            ClassBoResp classBoResp = new ClassBoResp();
            classBoResp.setClassName(classPoResp.getClassName());
            classBoRespList.add(classBoResp);
        }
        classListBoResp.setClassBoRespList(classBoRespList);
        return classListBoResp;
    }


    @Override
    public ClassListBoResp listAllClasses() {
        //从数据库中获取所有的行政班
        List<ClassPoResp> allClass = classMapper.getAllClass();
        ClassListBoResp classListBoResp = new ClassListBoResp();

        classListBoResp.setClassBoRespList(new ArrayList<>());
        allClass.forEach(classPoResp -> {
            ClassBoResp classBoResp = new ClassBoResp(classPoResp.getClassName());
            classListBoResp.getClassBoRespList().add(classBoResp);
        });
        return classListBoResp;
    }
}
